<?php
require_once("common.inc.php");
if(!$user) header("Location: login.php");



$requestMethod = $_SERVER["REQUEST_METHOD"];
if($requestMethod=="GET"){
    $id = getParam("Id"); 
    $sql ="select * from `article` where Id=$id";
    $detail = ["Title"=>"","Content"=>"","UpdateTime"=>"","AuthorName"=>""];
    $conn = createDb();
    $rs = $conn->query($sql);
    if($conn->error) die($conn->error);
    $detail = $rs->fetch_assoc();
    //if($detail["AuthorId"]!==$currentUser["Id"]) header("Location: login.html");
}else{
$id = getParam("id"); 
$title = $_POST["Title"];
$content = $_POST["Content"];
$user = $_SESSION["user"];
$updateTime=date_format(new DateTime(),"Y-m-d H:i:s");
$user = $_SESSION["user"];
$sql = "UPDATE `article` SET `Title`='$title',`Content`='$content',`UpdateTime`='$updateTime' WHERE 
Id=$id AND AuthorId=".$user["Id"]; 
$conn = new mysqli("localhost","root","","myblog");
$rs = $conn->query($sql);
if($conn->error) die($conn->error);
header("Location: list3.php");die("Ok");
}


//$detail =["Title"=>"","Content"=>"","UpdateTime"=>"","AuthorName"=>""];
require_once("header.inc.php");
?>


    <form method="post" action="article_modify2.php?id=<?=$id ?>" class="dataset">
        <div class="field">
            <label>
                标题
            </label>
            <input type="text" name="Title" value="<?=$detail["Title"]?>"/>
        </div>
        <div class="field">
            <label>
                内容
            </label>
            <textarea name= "Content"><?=$detail["Content"]?></textarea>
        </div>
        
        <div class="info">
            <?=$detail["AuthorName"]?>编辑于
            <?=$detail["UpdateTime"]?>
        </div>
        <div class="actions">
            <a href="list3.php">返回列表</a>
            <input type="submit" value="提交" />
            
        </div>
    </form>
<?php require_once("footer.inc.php");?>
